//
//  MerchantServicesViewController.m
//  BabyAndBabyDriver
//
//  Created by 尹宁 on 16/8/18.
//  Copyright © 2016年 范琦. All rights reserved.
//

#import "MerchantServicesViewController.h"
#import "MerchantServicesTableViewCell.h"
#import "MerchantListModel.h"
@interface MerchantServicesViewController ()<UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *listArr;
@end

@implementation MerchantServicesViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"服务商户";
    _listArr = [NSMutableArray array];
    [self creatTableView];
    [self getListData];
}

- (void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = YES;
}

- (void)creatTableView
{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, KSCREENWIDTH, KSCREENHEIGHT) style:UITableViewStyleGrouped];
    _tableView.contentInset = UIEdgeInsetsMake(-30, 0, 0, 0);
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [_tableView registerNib:[UINib nibWithNibName:@"MerchantServicesTableViewCell" bundle:nil] forCellReuseIdentifier:@"cell"];
    
    [self.view addSubview:_tableView];
    _tableView.sectionFooterHeight = 0;
    _tableView.sectionHeaderHeight = 0;
}

- (void)getListData
{
    YTKNetHandle *api = [[YTKNetHandle alloc]initWithUrl:@"Auth/getMerchantList.json" paramDic:@{@"token":TOKEN} RegisterApiMethod:RequestMethodGet];
    [api startWithCompletionBlockWithSuccess:^(YTKBaseRequest *request) {
//        NSLog(@"%@", request.responseBody);
        NSDictionary *dic = request.responseBody[@"result"];
//        NSLog(@"%@",dic);
        NSArray *arr = dic[@"data"];
        for (NSDictionary *dic1 in arr) {
            MerchantListModel *model = [[MerchantListModel alloc] init];
            model.ID = dic1[@"id"];
            model.number = dic1[@"number"];
            model.name_merchant = dic1[@"name_merchant"];
            [_listArr addObject:model];
        }
        [_tableView reloadData];
    } failure:^(YTKBaseRequest *request) {
        
    }];
}

#pragma mark - TableView代理方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
   
    return _listArr.count;
}

//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
//{
//    return 3;
//}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 55;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MerchantServicesTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    MerchantListModel *model = _listArr[indexPath.row];
    cell.numeberLabel.text = [model.number stringValue];
    if ([model.name_merchant isKindOfClass:[NSString class]]) {
        cell.nameMerchantLabel.text = model.name_merchant;

    }else{
        NSNumber *num = (NSNumber *)model.name_merchant;
        cell.nameMerchantLabel.text = [num stringValue];

    }
    return cell;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
